home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ALPH.{_4 / FPU.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  119 lines

  1. #ifndef __ASM_ALPHA_FPU_H
  2. #define __ASM_ALPHA_FPU_H
  3.  
  4. /*
  5.  * Alpha floating-point control register defines:
  6.  */
  7. #define FPCR_INVD    (1UL<<49)    /* invalid op disable (opt.) */
  8. #define FPCR_DZED    (1UL<<50)    /* division by zero disable (opt.) */
  9. #define FPCR_OVFD    (1UL<<51)    /* overflow disable (optional) */
  10. #define FPCR_INV    (1UL<<52)    /* invalid operation */
  11. #define FPCR_DZE    (1UL<<53)    /* division by zero */
  12. #define FPCR_OVF    (1UL<<54)    /* overflow */
  13. #define FPCR_UNF    (1UL<<55)    /* underflow */
  14. #define FPCR_INE    (1UL<<56)    /* inexact */
  15. #define FPCR_IOV    (1UL<<57)    /* integer overflow */
  16. #define FPCR_UNDZ    (1UL<<60)    /* underflow to zero (opt.) */
  17. #define FPCR_UNFD    (1UL<<61)    /* underflow disable (opt.) */
  18. #define FPCR_INED    (1UL<<62)    /* inexact disable (opt.) */
  19. #define FPCR_SUM    (1UL<<63)    /* summary bit */
  20.  
  21. #define FPCR_DYN_SHIFT    58        /* first dynamic rounding mode bit */
  22. #define FPCR_DYN_CHOPPED (0x0UL << FPCR_DYN_SHIFT)    /* towards 0 */
  23. #define FPCR_DYN_MINUS     (0x1UL << FPCR_DYN_SHIFT)    /* towards -INF */
  24. #define FPCR_DYN_NORMAL     (0x2UL << FPCR_DYN_SHIFT)    /* towards nearest */
  25. #define FPCR_DYN_PLUS     (0x3UL << FPCR_DYN_SHIFT)    /* towards +INF */
  26. #define FPCR_DYN_MASK     (0x3UL << FPCR_DYN_SHIFT)
  27.  
  28. #define FPCR_MASK    0xfffe000000000000
  29.  
  30. /*
  31.  * IEEE trap enables are implemented in software.  These per-thread
  32.  * bits are stored in the "flags" field of "struct thread_struct".
  33.  * Thus, the bits are defined so as not to conflict with the
  34.  * floating-point enable bit (which is architected).  On top of that,
  35.  * we want to make these bits compatible with OSF/1 so
  36.  * ieee_set_fp_control() etc. can be implemented easily and
  37.  * compatibly.  The corresponding definitions are in
  38.  * /usr/include/machine/fpu.h under OSF/1.
  39.  */
  40. #define IEEE_TRAP_ENABLE_INV    (1UL<<1)    /* invalid op */
  41. #define IEEE_TRAP_ENABLE_DZE    (1UL<<2)    /* division by zero */
  42. #define IEEE_TRAP_ENABLE_OVF    (1UL<<3)    /* overflow */
  43. #define IEEE_TRAP_ENABLE_UNF    (1UL<<4)    /* underflow */
  44. #define IEEE_TRAP_ENABLE_INE    (1UL<<5)    /* inexact */
  45. #define IEEE_TRAP_ENABLE_MASK    (IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE |\
  46.                  IEEE_TRAP_ENABLE_OVF | IEEE_TRAP_ENABLE_UNF |\
  47.                  IEEE_TRAP_ENABLE_INE)
  48.  
  49. /* status bits coming from fpcr: */
  50. #define IEEE_STATUS_INV        (1UL<<17)
  51. #define IEEE_STATUS_DZE        (1UL<<18)
  52. #define IEEE_STATUS_OVF        (1UL<<19)
  53. #define IEEE_STATUS_UNF        (1UL<<20)
  54. #define IEEE_STATUS_INE        (1UL<<21)
  55.  
  56. #define IEEE_STATUS_MASK    (IEEE_STATUS_INV | IEEE_STATUS_DZE |    \
  57.                  IEEE_STATUS_OVF | IEEE_STATUS_UNF |    \
  58.                  IEEE_STATUS_INE)
  59.  
  60. #define IEEE_SW_MASK        (IEEE_TRAP_ENABLE_MASK | IEEE_STATUS_MASK)
  61.  
  62. #define IEEE_STATUS_TO_EXCSUM_SHIFT    16
  63.  
  64. #define IEEE_INHERIT    (1UL<<63)    /* inherit on thread create? */
  65.  
  66. /*
  67.  * Convert the software IEEE trap enable and status bits into the
  68.  * hardware fpcr format.
  69.  */
  70.  
  71. static inline unsigned long
  72. ieee_swcr_to_fpcr(unsigned long sw)
  73. {
  74.     unsigned long fp;
  75.     fp = (sw & IEEE_STATUS_MASK) << 35;
  76.     fp |= sw & IEEE_STATUS_MASK ? FPCR_SUM : 0;
  77.     fp |= (~sw & (IEEE_TRAP_ENABLE_INV
  78.               | IEEE_TRAP_ENABLE_DZE
  79.               | IEEE_TRAP_ENABLE_OVF)) << 48;
  80.     fp |= (~sw & (IEEE_TRAP_ENABLE_UNF | IEEE_TRAP_ENABLE_INE)) << 57;
  81.     return fp;
  82. }
  83.  
  84. #ifdef __KERNEL__
  85.  
  86. /* The following two functions don't need trapb/excb instructions
  87.    around the mf_fpcr/mt_fpcr instructions because (a) the kernel
  88.    never generates arithmetic faults and (b) call_pal instructions
  89.    are implied trap barriers.  */
  90.  
  91. static inline unsigned long rdfpcr(void)
  92. {
  93.     unsigned long tmp, ret;
  94.     __asm__ ("stt $f0,%0\n\t"
  95.          "mf_fpcr $f0\n\t"
  96.          "stt $f0,%1\n\t"
  97.          "ldt $f0,%0"
  98.         : "=m"(tmp), "=m"(ret));
  99.     return ret;
  100. }
  101.  
  102. static inline void wrfpcr(unsigned long val)
  103. {
  104.     unsigned long tmp;
  105.     __asm__ __volatile__ (
  106.         "stt $f0,%0\n\t"
  107.         "ldt $f0,%1\n\t"
  108.         "mt_fpcr $f0\n\t"
  109.         "ldt $f0,%0"
  110.         : "=m"(tmp) : "m"(val));
  111. }
  112.  
  113. extern unsigned long alpha_read_fp_reg (unsigned long reg);
  114. extern void alpha_write_fp_reg (unsigned long reg, unsigned long val);
  115.  
  116. #endif /* __KERNEL__ */
  117.  
  118. #endif /* __ASM_ALPHA_FPU_H */
  119.